// ==UserScript==
// @name         italent考勤
// @namespace    https://gitee.com/blb19900404/tampermonkey/tree/master
// @version      0.0.2
// @description  计算italent考勤合计时间统计
// @author       zf
// @match        https://www.italent.cn/portal/convoy/attendance*
// @icon         https://www.google.com/s2/favicons?domain=italent.cn
// @updateURL    https://gitee.com/blb19900404/tampermonkey/raw/master/script/italentDuration.js
// @downloadURL  https://gitee.com/blb19900404/tampermonkey/raw/master/script/italentDuration.js
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    const _fetch = window.fetch;
    window.fetch = async function (...arg) {
        if(/TableList/g.test(arg[0])){
            const data = await _fetch(...arg).then(res=>res.json());
            const sum = (data?.biz_data||[]).map(v=>v.WorkPeriodExcludeRestTime.value).reduce((a,b)=>Number(a) + Number(b))
            let durationDom = document.querySelector('#duration')
            if(!durationDom){
                durationDom = document.createElement('span');
                durationDom.id='duration'
                durationDom.style="position: absolute;top: 20px;left: 50%;color: red;font-size: 26px;z-index: 999;"
                document.querySelector('body').appendChild(durationDom);
            }

            durationDom.innerHTML=+sum.toFixed(2)
        }
        return _fetch(...arg)
    }
})();